#define upload(x)
		<div class="form-group">
			<div class="col-sm-10" id="_#(x.index??)_BTN">
				<label class="control-label no-padding-right" id="_#(x.index??)_upload" style="cursor:pointer;"><i class="fa fa-cloud-upload"></i>&nbsp;选择文件</label>&nbsp;&nbsp;
				<input type="hidden" id="_#(x.index??)" data-type="upload" name="token_#(table??x.table).#(x.index??)" #(x.required??) value="" data-key="上传" data-target="_#(x.index??)_upload" class="form-control"/>
			</div>
		</div>
		<div class="form-group">
		      <div class="box-footer">
	              <ul class="mailbox-attachments clearfix" id="_#(x.index??)_upload_preview">
	              </ul>
			  </div>
		</div>
		<link rel="stylesheet" href="/static/zyUpload/control/css/zyUpload.css" type="text/css">
		<link rel="stylesheet" href="/static/zyUpload/upload.css" type="text/css">
		<script charset="utf-8" src="/static/zyUpload/core/zyFile.js"></script>
		<script charset="utf-8" src="/static/zyUpload/control/js/zyUpload.js"></script>
		<script type="text/javascript">
		var extMap = new Map();
		extMap.put("image",".gif,.jpg,.jpeg,.png,.bmp");
		extMap.put("flash",".swf,.flv");
		extMap.put("media",".swf,.flv,.mp3,.mp4,.wav,.wma,.wmv,.mid,.avi,.mpg,.asf,.rm,.rmvb");
		extMap.put("file",".doc,.docx,.xls,.xlsx,.ppt,.pptx,.htm,.html,.txt,.zip,.rar,.gz,.bz2,.pdf");
		extMap.put("allfile",".gif,.jpg,.jpeg,.png,.bmp,.swf,.flv,.mp3,.mp4,.wav,.wma,.wmv,.mid,.avi,.mpg,.asf,.rm,.rmvb,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.htm,.html,.txt,.zip,.rar,.gz,.bz2,.pdf");
		function getFileExt(fileName){
			var index = fileName.lastIndexOf(".");
			return fileName.substr(index+1);
		}
		
		function getFileType(fileName) {
			var fileExt = getFileExt(fileName);
			var ext = extMap.get("image");
			if (ext.indexOf(fileExt) != -1) {
				return "fa fa-file-image-o";
			}
			ext = extMap.get("flash");
			if (ext.indexOf(fileExt) != -1) {
				return "fa fa-file-o";
			}
			ext = extMap.get("media");
			if (ext.indexOf(fileExt) != -1) {
				return "fa fa-file-video-o";
			}
			if (fileExt=="doc" ||fileExt=="docx" ) {
				return "fa fa-file-word-o";
			}else if(fileExt=="xls" ||fileExt=="xls"){
				return "fa fa-file-excel-o";
		    }else if(fileExt=="pdf"){
				return "fa fa-file-pdf-o";
		    }else if(fileExt=="ppt" ||fileExt=="pptx"){
				return "fa fa-file-powerpoint-o";
		    }else if(fileExt=="txt"){
				return "fa fa-file-text-o";
		    }else if(fileExt=="zip"){
				return "fa fa-file-zip-o";
		    }else{
				return "fa fa-file-o";
			}
		}
		
		$("#_#(x.index??)_upload").click(function(){
			_#(x.index??)_initupload();
		});
			
		function _#(x.index??)_initupload(){
			var fileArray=[];
			//页面层
			layer.open({
			  type: 1,
			  title: "文件上传",
			  area: ['650px', '400px'], //宽高
			  content: '<div id="_#(x.index??)_editor"></div>',
			  success: function(layero){
				  var extraFileUploadParams = { uploadType : "#(x.uploadType)",typeCode:"#(x.typeCode)",attachId:"#(x.attachId)",table:"#(x.table)",dir:"#(x.dir)"};
				  $("#_#(x.index??)_editor").zyUpload({
						width            :   "650px",                 // 宽度
						height           :   "370px",                 // 宽度
						itemWidth        :   "120px",                 // 文件项的宽度
						itemHeight       :   "100px",                 // 文件项的高度
						url              :   "/kindeditor/upload_#(x.batch==false?'json':'jsons')",  // 上传文件的路径
						batch            :   #(x.batch??true),
						extraFileUploadParams :extraFileUploadParams,
						accept           :   "#(x.accept??'image/png,image/jpeg,image/gif,image/jpg')",//.xls,.doc,.txt,.pdf
						multiple         :   true,                    // 是否可以多个文件上传
						dragDrop         :   true,                    // 是否可以拖动上传文件
						del              :   true,                    // 是否可以删除文件
						finishDel        :   true,  				  // 是否在上传文件完成后删除预览
						/* 外部获得的回调接口 */
						onSelect: function(files, allFiles){                    // 选择文件的回调方法
						
						},
						onDelete: function(file, surplusFiles){                     // 删除一个文件的回调方法
						},
						onSuccess: function(file,response){                    // 文件上传成功的回调方法
							var datas = JSON.parse(response);
						    if(#(x.batch??true)){
						    	for(var i=0;i<datas.length;i++){ 
						    		var data = datas[i];
						    	  	if(data.error==0){
						    	  		file_preview("_#(x.index??)_upload_preview",data);
							    	}else{
							    		layer.alert(data.msg, {icon: 2,title:"发生错误"});
							    	}
						    	} 
						    }else{
						    	if(datas.error==0){
						    		file_preview("_#(x.index??)_upload_preview",datas);
						    		   fileArray.push(datas.title);
						    	}else{
						    		layer.alert(datas.msg, {icon: 2,title:"发生错误"});
						    	}
						    }
						},
						onFailure: function(file){                    // 文件上传失败的回调方法
						},
						onComplete: function(responseInfo){           // 上传完成的回调方法
							var _name = $("#_#(x.index??)").attr("name").replace("token_", "");
							$("#_#(x.index??)").attr("name", _name);
							var fileds = $("#_#(x.index??)").val();
							if(#(x.batch??true)){
								var datas = JSON.parse(responseInfo);
								for(var i=0;i<datas.length;i++){ 
						    		var data = datas[i];
						    		fileArray.push(data.title);
						    	} 
							}
							if(fileds!=""){
								$("#_#(x.index??)").val(fileds + "," + fileArray.join(","));
							}else{
								$("#_#(x.index??)").val(fileArray.join(","));
							}
							layer.photos({
								  photos: '#_#(x.index??)_upload_preview'
								  ,closeBtn:1
								  ,full: true
								  ,scrollbar: true
								  ,shade: [0.5, '#393D49']
								  ,shadeClose:true
								  ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机
							}); 
							$("#form_token").val(1);
						}
					});
			  }
			});
		}
		
		
		function _#(x.index??)_inituploadview(ids, type){
			if(type == "view"){
				$("#_#(x.index??)_BTN").css("display", "none");
				
			}
			var attachid = ids;
		    if(attachid !=''){
		  	  var ajax = new $ax("/attach/findByIds", function(data){
					if (data.state == 'ok') {
						for(var i = 0;i<data.data.length;i++){
							var file=data.data[i];
							file.title = file.name;
							file_preview("_#(x.index??)_upload_preview",file);
						}
						clearLoading(appindex);
						return false;
					} else {
						clearLoading(appindex);
						layer.alert("发生错误", {icon: 2,title:"发生错误"});
						return false;
					}
				});
				var appindex = appLoading();
				ajax.set("attachid",attachid);
				ajax.start();
		    }
		    
			/* layer.photos({
				  photos: '#_#(x.index??)_upload_preview'
				  ,closeBtn:1
				  ,full: true
				  ,scrollbar: true
				  ,shade: [0.5, '#393D49']
				  ,shadeClose:true
				  ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机
			});  */
		}
		
		function _#(x.index??)_deleteImg(fileId){
			 layer.confirm('确认删除文件吗？', {
	                icon: 3,
	                btn: ['确定', '取消'] //按钮
	            }, function (index) {
	            	layer.close(index);
	             	var appindex = appLoading();
	    			var ajax = new $ax("/kindeditor/deleteFile", function(data){
	    				if (data.state == 'ok') {
	    					clearLoading(appindex);
	    					var fileds = $("#_#(x.index??)").val();
	    					var fileArry = fileds.split(',');
	    					var index = fileArry.indexOf(fileId);
	    					if (index > -1) {
	    						fileArry.splice(index, 1);
	    					}
	    					$("#_#(x.index??)").val(fileArry.join(","));
	    					$("#li_"+fileId).remove();
	    					
	    					var _name = $("#_#(x.index??)").attr("name").replace("token_", "");
	    					$("#_#(x.index??)").attr("name", _name);
	    					$("#form_token").val(1);
	    					return false;
	    				} else {
	    					clearLoading(appindex);
	    					if(data.state == 'fail'){
	    						layer.alert(data.msg, {icon: 5,title:"发生错误"});
	    					}
	    					else{
	    						layer.msg(data.msg, {icon: 2,time:2000});
	    					}
	    					return false;
	    				}
	    			});
	    			ajax.set("fileId",fileId);
	    			ajax.start();	
	            }, function () {
	              
	        });
		}
		
		
		function file_preview(id,data){
			var fileType = getFileType(data.name);
			var attachImage = "fa fa-paperclip";
			var type = "file";
			if("fa fa-file-image-o"==fileType){
				attachImage = "fa fa-camera";
				type = "image";
			}
			var url = "/kindeditor/renderFile/" + data.id;
			var size = (data.filesize/1024).toFixed(1);
			var fileName = data.name;
			fileName = fileName.interceptString(13);
			var fileView = new StringBuffer();
			fileView.append("<li id='li_"+data.title+"' style='position:relative;'>");
			if(type=="image"){
				var layimg = "<img id='img_"+data.title+"'  layer-pid='img_"+data.title+"' layer-src='"+data.url+"' src='"+data.url+"' style='cursor:pointer;width:#(x.width??'198px');height:#(x.height??'137px');'></img>";
				fileView.append("<span class=\"mailbox-attachment-icon has-img\">");
				fileView.append(layimg);
				fileView.append("</span>");
			}else{
				fileView.append("<span class=\"mailbox-attachment-icon\">");
				fileView.append("<i class='"+fileType+"'></i>");
				fileView.append("</span>");
			}
			fileView.append("<div class=\"mailbox-attachment-info\">");
			fileView.append(" <a href=\"#\" class=\"mailbox-attachment-name\" title='"+data.name+"'><i class='"+attachImage+"'></i>");
			fileView.append(fileName);
			fileView.append("</a>");
			fileView.append("<span class=\"mailbox-attachment-size\">");
			fileView.append(size+" KB");
			fileView.append("<a href='"+url+"' target='_blank' class=\"btn btn-default btn-xs pull-right\"><i class=\"fa fa-cloud-download\"></i></a>");
			fileView.append("</span>");
			fileView.append("</div><i class='fa fa-times img-delete' onclick=\"_#(x.index??)_deleteImg('"+data.title+"')\"></i>");
			fileView.append("</li>");
			$("#"+id).append(fileView.toString());
		}
		</script>
#end
